package com.dgut.staffmodule.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(name = "t_department")
// @JsonIgnoreProperties(value={"staffs"})
public class Department {
	private Long id;// 部门id
	private String deptName;// 部门名称
	private int count;// 部门人数
	@DateTimeFormat(pattern = "yyyy/MM/dd")
	private Date setupDate;// 部门成立日期

	private List<Staff> staffs = new ArrayList<Staff>();// 部门与员工关系是一对多
	private List<Position> positions = new ArrayList<Position>();// 部门与职位关系是一对多

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public Long getId() {
		return id;
	}

	@Column(nullable = false, unique = true)
	public String getDeptName() {
		return deptName;
	}

	public int getCount() {
		return count;
	}

	@JsonFormat(pattern = "yyyy/MM/dd", timezone = "GMT+8")
	public Date getSetupDate() {
		return setupDate;
	}

	// 部门与员工的关系是一对多
	@JsonIgnore
	@OneToMany(mappedBy = "department")
	public List<Staff> getStaffs() {
		return staffs;
	}

	// 部门与职位的关系是一对多
	@JsonIgnore
	@OneToMany(mappedBy = "department")
	public List<Position> getPositions() {
		return positions;
	}

	public void setStaffs(List<Staff> staffs) {
		this.staffs = staffs;
	}

	public void setPositions(List<Position> positions) {
		this.positions = positions;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setDeptName(String deptName) {
		this.deptName = deptName;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public void setSetupDate(Date setupDate) {
		this.setupDate = setupDate;
	}

	@Override
	public String toString() {
		return "Department [id=" + id + ", deptName=" + deptName + ", count=" + count + ", setupDate=" + setupDate
				+ "]";
	}

}
